/**
 * ----------------------------------------------------------------------------
 * Copyright Jens Konopka
 * 
 * Alle Rechte vorbehalten.
 * Licence: Apache 2.0
 * ----------------------------------------------------------------------------
 *
 * created on 02.03.2012 by jkonopka
 */
package de.sql.toolkit.provider;

import java.io.Serializable;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import de.sql.toolkit.manager.ConnectionManager;
import de.sql.toolkit.util.SqlUtil;

/**
 * @author jkonopka
 * 
 */
public class SchemaProvider implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5987082403563816011L;

	/**
	 * @return
	 * @throws Exception
	 */
	public List<String> select() throws Exception {
		final List<String> list = new ArrayList<String>();
		final Connection connection = ConnectionManager.getConnection();
		ResultSet result = null;

		try {

			final DatabaseMetaData metaData = connection.getMetaData();
			result = metaData.getCatalogs();
			while (result.next()) {
				final String tablename = result.getString("TABLE_CAT");
				list.add(tablename);
			}

		} finally {
			SqlUtil.close(result);
		}
		return list;
	}

}
